<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  // var obj = {
  //   id: 1,
  //   name: 'andy',
  //   msg: {
  //     age:18
  //   }
  // };
  // var o = {};
  // for(var k in obj){
  //   o[k] = obj[k]
  // }
  // console.log(o);
  // console.log(obj);
  // o.msg.age = 20;

  var obj = {
    id: 1,
    name: 'andy',
    msg: {
      age:18
    }
  };
  var o = {};
  function deepCopy(newObj, oldObj){
    for(var k in oldObj){
      var item = oldObj[k];
      if(item instanceof Array){
        newObj[k] = [];
        deepCopy(newObj[k], item)
      } else if(item instanceof Object) {
        newObj[k] = {};
        deepCopy(newObj[k], item)
      } else {
        newObj[k] = item
      }
    }
  }

  deepCopy(o, obj);
  console.log(o);
  o.msg.age = 20;
  console.log(obj); // msg: {age: 20}

</script>
</body>
</html>